package cn.bytecollege.service;

import cn.bytecollege.dao.VipDao;
import cn.bytecollege.entity.Page;
import cn.bytecollege.entity.Vip;

import java.util.List;

public class VipService {
    private VipDao vipDao=null;
    public VipService(){
        vipDao=new VipDao();
    }

    /**
     * 根据id删除vip
     * zxy
     */
    public int delete(int vipId){
        return vipDao.delete(vipId);
    }
    /**
     * @author LH
     * 通过身份证号查询vip信息
     * @param idNumber
     * @return
     */
    public Vip findByIdNumber(String idNumber){
        return vipDao.findByIdNumber(idNumber);
    }

    /**
     * 分页查询所有vip
     * @author Mr.East
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Page<Vip> findByPage(int pageIndex, int pageSize){
        List<Vip> list = vipDao.findByPage(pageIndex,pageSize);
        int count = vipDao.count();
        Page<Vip> page = new Page<>();
        page.setCurrentIndex(pageIndex);
        page.setPageSize(pageSize);
        page.setTotal(count);
        page.setTotalPage(count);
        page.setPageIndex();
        page.setList(list);
        return page;
    }

    /**
     * 新增vip信息
     * @author Mr.East
     * @param vip
     * @return
     */
    public int save(Vip vip){
        return vipDao.save(vip);
    }

    /**
     * 更新会员信息
     * @author Mr.East
     * @param vip
     * @return
     */
    public int update(Vip vip){
        return vipDao.update(vip);
    }

    /**
     * 接受vipDao中传来的方法返回集合并继续准备好
     * @author Mr.East & HJ
     * @param vipId
     * @return
     */
    public  Vip findByVipId (Integer vipId){
        List<Vip> list = vipDao.findByVipId(vipId);
        Vip vip = null;
        if (list.size()>0){
            vip = list.get(0);
        }
        return vip;
    }
    public int count(){
        return vipDao.count();
    }


}

